package com.bw.zg3.notice

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bw.base.entity.GGEntityResultItem
import com.bw.base.net.ApiServer

class NoticeDataSource(val apiServer: ApiServer):PagingSource<Int,GGEntityResultItem>() {

    override fun getRefreshKey(state: PagingState<Int, GGEntityResultItem>): Int? {
      return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, GGEntityResultItem> {
       try {
           val currentPage = params.key ?: 0
           val notices = apiServer.getGG(currentPage, 10)
          val nextPage= if (notices.data.size==10)currentPage+1 else null
           return LoadResult.Page(notices.data,null,nextPage)


       }catch (e:Exception){
           return LoadResult.Error(e)
       }
    }
}